package com.foodapp.back.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.foodapp.back.common.Result;
import com.foodapp.back.service.OrderService;
import com.foodapp.back.vo.OrderVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 管理员订单控制器
 */
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {

    @Resource
    private OrderService orderService;

    /**
     * 分页查询订单列表
     */
    @GetMapping("/list")
    public Result<Page<OrderVO>> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) Long restaurantId,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String orderNo) {
        
        Page<OrderVO> result = orderService.getAdminOrderList(page, size, restaurantId, status, orderNo);
        return Result.success(result);
    }

    /**
     * 获取订单详情
     */
    @GetMapping("/{id}")
    public Result<OrderVO> getById(@PathVariable Long id) {
        OrderVO orderVO = orderService.getOrderDetail(id);
        return Result.success(orderVO);
    }

    /**
     * 更新订单状态
     */
    @PutMapping("/{id}/status")
    public Result<Boolean> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
        boolean result = orderService.updateOrderStatus(id, status);
        return Result.success(result);
    }
}
